package com.yunchao.maintenance

import android.app.Application
import android.content.Context
import androidx.multidex.MultiDex
import com.yunchao.feature.base.baseModule
import com.yunchao.feature.base.domain.utils.FileLoggingTree
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.GlobalContext
import timber.log.Timber

class MaintenanceApplication : Application() {


    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)
        MultiDex.install(this)
    }

    override fun onCreate() {
        super.onCreate()
        initKoin()
        initTimber()
    }

    private fun initTimber() {
        Timber.plant(if (BuildConfig.DEBUG) Timber.DebugTree() else FileLoggingTree(this))
    }

    private fun initKoin() {
        GlobalContext.startKoin {
            androidLogger()
            androidContext(this@MaintenanceApplication)
            modules(appModule)
            modules(baseModule)
        }

    }
}